package com.lam.framework.mybatis;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.lam.common.utils.StringUtils;

/**
 * Mybatis属性配置拦截处理
 * 
 * @author lam
 */
@Aspect
//@Component
public class MybatisAspect {
	
	// 配置织入点
	@Pointcut("execution(* org.mybatis.spring.boot.autoconfigure.MybatisProperties.getTypeAliasesPackage(..))")
    public void pointCut(){}
    
    @Before("pointCut()")
	public void around(JoinPoint joinPoint) throws Throwable {
    	
    	MybatisPlusProperties mybatisProperties = (MybatisPlusProperties)joinPoint.getTarget();
    	if(StringUtils.contains(mybatisProperties.getTypeAliasesPackage(), "*")) {
    		mybatisProperties.setTypeAliasesPackage(MybatisUtil.scanTypeAliasesPackage(mybatisProperties.getTypeAliasesPackage()));
    	}
	}

}
